package com.gemme.gemme.view;

import android.content.Context;
import android.view.View;

import com.gemme.gemme.R;

public class FaPiaoDialog {

    boolean isPerson = true;
    boolean isDetail = true;
    RoundCheckBox cb_person;
    RoundCheckBox cb_danwei;
    RoundCheckBox cb_product_detil;
    RoundCheckBox cb_product_type;
    FabuPersonView fabuPersonView;
    FabuDanweiView fabuDanweiView;
    private Context mContext;

    public void showDialog(Context mContext) {
        this.mContext = mContext;
        BottomDialog dialog = new BottomDialog(mContext, R.layout.fapiao_dialog,
                new int[]{R.id.close});

        initView(dialog.getView());
        dialog.show();
        dialog.setOnBottomItemClickListener(new BottomDialog.OnBottomItemClickListener() {
            @Override
            public void onBottomItemClick(BottomDialog dialog, View view) {
                switch (view.getId()) {
                    case R.id.close:
                        dialog.dismiss();
                        break;

                }
            }
        });
    }

    private void initView(View view) {
        TvEditText shou_tel = view.findViewById(R.id.shou_tel);
        TvEditText shou_xinxi = view.findViewById(R.id.shou_xinxi);

        cb_person = view.findViewById(R.id.cb_person);
        cb_danwei = view.findViewById(R.id.cb_danwei);

        cb_product_detil = view.findViewById(R.id.cb_product_detil);
        cb_product_type = view.findViewById(R.id.cb_product_type);


        fabuPersonView = view.findViewById(R.id.fabuPersonView);
        fabuDanweiView = view.findViewById(R.id.fabuDanweiView);

        shou_tel.setLeftText("收票人手机").setRightHintText("请填写收票人手机");
        shou_xinxi.setLeftText("收票人信息").setRightHintText("请填写收票人信息");

        controlPersonOrdanwei();
        setIsPerson();

        controlProductDetail();
    }

    private void controlProductDetail() {


        cb_product_detil.setOnChangeLIstener(new OnChangeLIstener() {
            @Override
            public void onChangeLIstener() {
                boolean checked = cb_product_detil.isChecked();
                isDetail = checked;
                setIsDetail();
            }
        });
        cb_product_type.setOnChangeLIstener(new OnChangeLIstener() {
            @Override
            public void onChangeLIstener() {
                boolean checked = cb_product_type.isChecked();
                isDetail = !checked;
                setIsDetail();
            }
        });
    }

    private void setIsDetail() {
        cb_product_detil.setChecked(isDetail);
        cb_product_type.setChecked(!isDetail);
    }


    private void setIsPerson() {
        if (isPerson) {
            fabuPersonView.setVisibility(View.VISIBLE);
            fabuDanweiView.setVisibility(View.GONE);

        } else {
            fabuPersonView.setVisibility(View.GONE);
            fabuDanweiView.setVisibility(View.VISIBLE);
        }
        cb_person.setChecked(isPerson);
        cb_danwei.setChecked(!isPerson);

    }

    private void controlPersonOrdanwei() {
        cb_person.setOnChangeLIstener(new OnChangeLIstener() {
            @Override
            public void onChangeLIstener() {
                boolean checked = cb_person.isChecked();
                isPerson = checked;
                setIsPerson();
            }
        });
        cb_danwei.setOnChangeLIstener(new OnChangeLIstener() {
            @Override
            public void onChangeLIstener() {
                boolean checked = cb_person.isChecked();
                isPerson = !checked;
                setIsPerson();
            }
        });
    }
}
